package cn.demomaster.quickui_sample.ui.fragment.helper;

import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.demomaster.quickcompat.listener.OnDoubleClickListener;
import com.demomaster.quickcompat.listener.OnMultClickListener;
import com.demomaster.quickcompat.widget.button.QuickButton;

import java.util.ArrayList;
import java.util.List;

import cn.demomaster.quickrouter.fragment.QuickFragment;
import cn.demomaster.quickui.annotation.ActivityPager;
import cn.demomaster.quickui.annotation.ResType;
import cn.demomaster.quickui_sample.R;

/**
 * Squirrel桓
 * 2018/8/25
 */

@ActivityPager(name = "异常捕获", preViewClass = TextView.class, resType = ResType.Custome)
public class ErrorTestFragment extends QuickFragment {

    QuickButton btn_error_01;
    QuickButton btn_error_02;
    QuickButton btn_error_03;
    QuickButton btn_error_04;
    QuickButton btn_double_click;
    QuickButton btn_three_click;

    @NonNull
    @Override
    public View onGenerateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View mView = inflater.inflate(R.layout.fragment_layout_errortest, null);
        return mView;
    }

    public void initView(View rootView) {
        btn_error_01 = findViewById(R.id.btn_error_01);
        btn_error_02 = findViewById(R.id.btn_error_02);
        btn_error_03 = findViewById(R.id.btn_error_03);
        btn_error_04 = findViewById(R.id.btn_error_04);
        btn_double_click = findViewById(R.id.btn_double_click);
        btn_three_click = findViewById(R.id.btn_three_click);
        getActionBarTool().setTitle("异常捕获");
        btn_error_01.setOnClickListener(v -> {
            int a = 0;
            int b = 1;
            int c = b / a;
        });
        btn_error_02.setOnClickListener(v -> {
            Paint paint = null;
            paint.setColor(Color.RED);
        });
        btn_error_03.setOnClickListener(v -> new Thread(new Runnable() {
            @Override
            public void run() {
                Object linearLayout = new LinearLayout(getContext());
                RelativeLayout relativeLayout = (RelativeLayout) linearLayout;
            }
        }).start());
        /*btn_file_browser.setOnClickListener(v -> {
                    // String[] paths = new String[]{};
                    ArrayList<String> paths = new ArrayList<>();
                    paths.add(mContext.getFilesDir().getParentFile().getAbsolutePath());
                    paths.add(mContext.getExternalCacheDir().getAbsolutePath());
                    paths.add(mContext.getExternalFilesDir(null).getAbsolutePath());

                    Intent intent = new Intent();
                    Bundle bundle = new Bundle();
                    //bundle.putString("DIR_PATH_KEY", mContext.getExternalFilesDir("").getParentFile().getAbsolutePath());
                    bundle.putStringArrayList("DIR_PATHS_KEY", paths);
                    intent.putExtras(bundle);
                    startFragment(new FileExplorerFragment(), android.R.id.content, intent);
                }
        );
*/
        btn_error_04.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                error();
            }
        });

        btn_double_click.setOnClickListener(new OnDoubleClickListener() {
            @Override
            public void onDoubleClick(View v) {
                Toast.makeText(mContext, "double click", Toast.LENGTH_SHORT).show();
            }
        });
        btn_three_click.setOnClickListener(new OnMultClickListener(3, 300) {
            @Override
            public void onClickEvent(View v) {
                Toast.makeText(mContext, "three click", Toast.LENGTH_SHORT).show();
            }
        });
    }

   /* public void initActionBarLayout(ActionBarLayout2 actionBarLayoutOld) {
        int i = (int) (Math.random() * 10 % 4);
        actionBarLayoutOld.setTitle("audio play");
        actionBarLayoutOld.setHeaderBackgroundColor(Color.RED);

    }*/

    public void error(){
        List<String> stringList = new ArrayList<>();
        stringList.add("a");
        stringList.add("b");
        for (String str : stringList) {
            stringList.remove(str);
        }
    }
}